﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyCompany.MyProject.Model
{
    /// <summary>
    /// 通用返回信息类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class MessageModel<T>
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public int status { get; set; } = 200;

        /// <summary>
        /// 操作是否成功
        /// </summary>
        public bool success { get; set; } = false;

        /// <summary>
        /// 返回信息
        /// </summary>
        public string msg { get; set; } = string.Empty;

        /// <summary>
        /// 开发者信息
        /// </summary>
        public string? msgDev { get; set; }

        /// <summary>
        /// 返回数据集合
        /// </summary>
        public T? response { get; set; }

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static MessageModel<T> Success(string msg)
        {
            return Message(true, msg, default);
        }
        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="response"></param>
        /// <returns></returns>
        public static MessageModel<T> Success(string msg,T response)
        {
            return Message(true, msg, response);
        }

        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static MessageModel<T> Fail(string msg)
        {
            return Message(false, msg, default);
        }

        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="response"></param>
        /// <returns></returns>
        public static MessageModel<T> Fail(string msg, T response)
        {
            return Message(false, msg, response);
        }

        /// <summary>
        /// 返回消息
        /// </summary>
        /// <param name="success"></param>
        /// <param name="msg"></param>
        /// <param name="response"></param>
        /// <returns></returns>
        public static MessageModel<T> Message(bool success, string msg,T? response)
        {
            return new MessageModel<T>() { msg=msg,response=response,success=success};
        }
    }

    /// <summary>
    /// 返回消息实体
    /// </summary>
    public class MessageModel
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public int status { get; set; } = 200;

        /// <summary>
        /// 操作是否成功
        /// </summary>
        public bool success { get; set; } = false;

        /// <summary>
        /// 返回信息
        /// </summary>
        public string msg { get; set; } = string.Empty;

        /// <summary>
        /// 返回数据集合
        /// </summary>
        public object? response { get; set; }
    }
}
